package com.yn.bigevent.controller;

import com.yn.bigevent.pojo.Result;
import com.yn.bigevent.utils.AliOssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;
@CrossOrigin
@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        //保证文件名是唯一的，防止文件覆盖
        String filename= UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        //file.transferTo(new File("E:\\downloadProject\\bigevent\\file\\"+originalFilename));
        AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success("url地址");
    }
}
